<template>
  <div class='module relative'>
    <div class='title'>总盈亏对比</div>
    <div ref='charDom' class="charDom" style='height:300px;width:330px;'></div>
    <div class="absolute waveBox positionAddress1">
      <div class="waveInnerBox relative"></div>
      <div class="iconBox relative color-shallowBlue font18 iconfont icon-a-ziyuan12"></div>
    </div>
    <div class="absolute waveBox positionAddress2">
      <div class="waveInnerBox relative"></div>
      <div class="iconBox relative color-shallowRed font18 iconfont icon-a-ziyuan13"></div>
    </div>
  </div>
</template>

<script>
const echarts = require('echarts')

export default {
  props: ['dataList'],
  components: {},
  data(){
    return {
      currentNav: '',
      myChart: null
    }
  },
  watch: {
    dataList () {
      this.getOption()
    }
  },
  mounted(){
    this.myChart = echarts.init(this.$refs.charDom)
    if (!this.dataList.length) return
    this.getOption()
  },
  methods: {
    getOption () {
      let index = this.dataList.length - 1
      this.myChart.setOption({
        title: { text: '' },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'none'
          },
          borderWidth: 0,
          borderColor: '#104db1',
          backgroundColor: '#104db1',
          textStyle: {
            color: '#fff'
          }
        },
        xAxis: {
          data: ['实际收入', '实际投入'],
          axisLabel: {
            show: false
          },
          axisLine: {
            show: false
          },
          axisTick: {
            show: false
          },
          splitLine: {
            show: false
          }
        },
        yAxis: {
          nameTextStyle: {
            color: 'white'
          },
          axisLabel: {
            color: 'white',
            show: false
          },
          axisLine: {
            show: false
          },
          splitLine: {
            show: false
          }
        },
        series: [
          {
            type: 'bar',
            barWidth: 45,
            itemStyle: {
              borderRadius: [4, 4, 0, 0]
            },
            label: {
              show: true,
              position: 'top',
              borderWidth: 0,
              color: '#fff'
            },
            data: [
              {
                value: this.dataList[index]['实际收入'],
                name: '实际收入',
                itemStyle: {
                  normal: {
                    color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{
                      offset: 0,
                      color: "#0865c6"
                    }, {
                      offset: 0.6,
                      color: "#45d5f9"
                    }], false)
                  }
                }
              },
              {
                value: this.dataList[index]['实际投入'],
                name: '实际投入',
                itemStyle: {
                  normal: {
                    color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{
                      offset: 0,
                      color: "#fe6f0f"
                    }, {
                      offset: 0.6,
                      color: "#f1b238"
                    }], false)
                  }
                }
              }
            ]
          },
          {
            name: '',
            type: 'line',
            markLine: {
              label: {
                show: false,
              },
              silent: true,
              lineStyle: {
                color: 'white'
              },
              symbol: 'none',
              data: [
                {
                  name: '',
                  yAxis: this.dataList[index]['实际收入']
                }
              ]
            }
          },
          {
            name: '',
            type: 'line',
            markLine: {
              label: {
                show: false
              },
              silent: true,
              lineStyle: {
                color: 'white'
              },
              symbol: 'none',
              data: [
                {
                  name: '',
                  yAxis: this.dataList[index]['实际投入']
                }
              ]
            }
          }
        ]
      })
    }
  }
}
</script>
<style scoped lang='less'>
.module {
  background-image: url(../../../../assets/chartBg/FinanceBoard4.png);
  background-repeat: no-repeat;
  background-position: center center;
  background-size: 100% 100%;

  width: 392px;
  height: 335px;

  display: flex;
  justify-content: flex-start;
  align-items: center;
  flex-flow: column;
  .charDom{
    z-index: 99;
  }
  .title {
    font-size: 24px;
    font-weight: 400;
    color: #E9F2F9;
    text-align: center;
    padding-top: 18px;
  }
  .waveBox{
    height: 12%;
    width: 24%;
    border-radius: 50% 50%;
    box-shadow: inset 0.0rem 0.0rem 0.10rem #1e5ebd;
    z-index: 1;
  }
  .waveInnerBox{
    height: 70%;
    width: 80%;
    border-radius: 50% 50%;
    box-shadow: inset 0.0rem 0.0rem 0.10rem #1e5ebd;
    z-index: 1;
    left: 10%;
    top: 10%;
  }
  .positionAddress1{
    bottom: 15%;
    left: 21%;
  }
  .positionAddress2{
    bottom: 15%;
    right: 21%;
  }
  .iconBox{
    width: 30px;
    height: 30px;
    text-align: center;
    line-height: 30px;
    font-size: 24px;
    top: 50%;
    left: 35%;
  }
}

</style>
